package com.qeegoo.b2bautozityp.moudle.good.viewmodel.carmodel;

import android.databinding.ObservableArrayList;
import android.databinding.ObservableField;
import android.databinding.ObservableList;

import com.qeegoo.b2bautozityp.BR;
import com.qeegoo.b2bautozityp.R;
import com.qeegoo.b2bautozityp.moudle.good.model.CarModelBean;
import com.qeegoo.b2bautozityp.moudle.good.view.GoodsActivity;

import base.lib.util.ActivityManager;
import me.tatarka.bindingcollectionadapter.ItemView;

/**
 * 王少岩 在 2017/9/22 创建了它
 */

public class CarModelSelectViewModel {
    public ObservableField<String> selectText = new ObservableField<>("已选择0款车型");
    public ObservableList<CarModelBeanViewModel> items = new ObservableArrayList<>();
    public ItemView itemView = ItemView.of(BR.viewModel, R.layout.adapter_goods_carmodel_item_selected);

    public CarModelSelectViewModel() {
        selectText.set("已选择" + ((GoodsActivity)ActivityManager.getActivity()).getViewModel().getSelectBeans().size() + "款车型");
        for (CarModelBean bean : ((GoodsActivity)ActivityManager.getActivity()).getViewModel().getSelectBeans()) {
            items.add(new CarModelBeanViewModel(this, bean));
        }
    }

    public void delItem(CarModelBeanViewModel item){
        items.remove(item);
        ((GoodsActivity)ActivityManager.getActivity()).getViewModel().getSelectBeans().remove(item.mBean);
        selectText.set("已选择" + ((GoodsActivity)ActivityManager.getActivity()).getViewModel().getSelectBeans().size() + "款车型");
        ((GoodsActivity) ActivityManager.getActivity()).setProperty_no_close("适用车型", "", "已选择" + ((GoodsActivity) ActivityManager.getActivity()).getViewModel().getSelectBeans().size() + "款车型");
    }
}
